<?php

$params = require(__DIR__ . '/params.php');

$config = [
    'id' => 'basic',
    'basePath' => dirname(__DIR__),
    'bootstrap' => ['log'],
    'components' => [
        'request' => [
            // cookie验证key
            'cookieValidationKey' => 'MaoAQiuHaoDaiHaoDaiHaoDaiHaoDaiHaoDaiHaoDai',
        ],
        // 缓存配置
        'cache' => [
            // 使用文件缓存
            'class' => 'yii\caching\FileCache',
        ],
        // 用户登录记录工具配置
        'user' => [
            'identityClass' => 'app\models\UserIdentity',
            'enableAutoLogin' => true,
            'loginUrl' => ['user/login'],
        ],
        // 错误处理地址
        'errorHandler' => [
            'errorAction' => 'frontend/site/error',
        ],
        'mailer' => [
            'class' => 'yii\swiftmailer\Mailer',
            // send all mails to a file by default. You have to set
            // 'useFileTransport' to false and configure a transport
            // for the mailer to send real emails.
            'useFileTransport' => true,
        ],
        // 日志记录配置
        'log' => [
            'traceLevel' => YII_DEBUG ? 3 : 0,
            'targets' => [
                [
                    'class' => 'yii\log\FileTarget',
                    'levels' => ['error', 'warning'],
                ],
            ],
        ],
        // 引入数据库配置
        'db' => require(__DIR__ . '/db.php'),
        // url改写管理
        'urlManager' => [
            'enablePrettyUrl' => true,
            'showScriptName' => false,
            'rules' => [
                // 通用的<controller><action>匹配
                '/<controller:([\w+]+\-)*[\w+]+>/<action:([\w+]+\-)*[\w+]+>' => '/frontend/<controller>/<action>',

                // 通用的前台<controller>匹配
                '/<controller:([\w+]+\-)*[\w+]+>\/?/' => '/frontend/<controller>/index',
            ],
        ],
    ],
    'params' => $params,
    'defaultRoute' => '/frontend/',
    // 模块加载配置
    'modules' => [
        'backend' => [
            'class' => 'app\modules\backend\backend',
            'layout'=>'main'
        ],
        'frontend' => [
            'class' => 'app\modules\frontend\frontend',
            'layout'=>'main'
        ],
    ],
];

if (YII_ENV_DEV) {
    // configuration adjustments for 'dev' environment
    $config['bootstrap'][] = 'debug';
    $config['modules']['debug'] = [
        'class' => 'yii\debug\Module',
    ];

    $config['bootstrap'][] = 'gii';
    $config['modules']['gii'] = [
        'class' => 'yii\gii\Module',
    ];
}

return $config;
